import '@/assets/js/console'
import Vue from 'vue'
import App from './App.vue'
import router from '@/router'
import store from '@/store'
import '@/assets/css/basic.css'
import 'amfe-flexible'
import Vant from 'vant'
import 'vant/lib/index.css'
import FastClick from 'fastclick'
import VConsole from 'vconsole'
import Middleware from './middleware'
import filters from './filters'

if (process.env.VUE_APP_USE_VCONSOLE === 'true') {
  // eslint-disable-next-line no-unused-vars
  const vConsole = new VConsole()
}

Vue.config.productionTip = false
Vue.prototype.$toast = Vant.Toast

Vue.use(Middleware)
Vue.use(filters)
Vue.use(Vant)
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

window.addEventListener('load', () => {
  FastClick.attach(document.body)
  // 解决ios移动端input调软键盘问题
  FastClick.prototype.focus = function (targetElement) {
    let length
    const isIphone = navigator.userAgent.indexOf('iPhone') !== -1
    if (
      isIphone &&
      targetElement.setSelectionRange &&
      targetElement.type.indexOf('date') !== 0 &&
      targetElement.type !== 'time' &&
      targetElement.type !== 'month' &&
      targetElement.type !== 'email'
    ) {
      length = targetElement.value.length
      targetElement.setSelectionRange(length, length)
      /* 修复bug ios 11.3不弹出键盘，这里加上聚焦代码，让其强制聚焦弹出键盘 */
      targetElement.focus()
    } else {
      targetElement.focus()
    }
  }
})
